home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / bind.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-30  |  8.3 KB  |  328 lines

  1. /*
  2.     GWAda Development Environment for 386/486 PCs   
  3.     Copyright (C) 1993, Arthur Vargas Lopes  & Michael Bliss Feldman
  4.                         vlopes@vortex.ufrgs.br mfeldman@seas.gwu.edu
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; version 2 of the License.    
  9.  
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20.  
  21. /* Bind.c */
  22.  
  23. #include <externs.h>
  24.  
  25. extern void AVL_MAKE_UNIT_DATE(AVL_EDIT_WINDOW_PTR w);
  26.  
  27. short first, last;
  28.  
  29. void AVL_SHOW_UNIT(AVL_BIND_PTR w, short cols)
  30. {
  31.     short i,  k;    
  32.     short co;
  33.     char msg[35];
  34.     char fmt[20];
  35.     sprintf(fmt," %cc %c-%ds", '%', '%', cols);
  36.  
  37.     k = avl_cur_unit / 9;
  38.     first = k * 9;
  39.     last = first + 8;
  40.     if (last >= avl_size) 
  41.         last = avl_size - 1;
  42.     
  43.     _settextposition(1,1);
  44.     _outtext("\n\n\n\n\n\n\n\n\n\n\n\n");
  45.     _outtext("\n\n\n\n\n\n\n\n\n\n\n\n");
  46.     k = 1;
  47.     for(i = first; i <= last; ++i)  {
  48.         _settextposition(k,1);
  49.         if (i == avl_cur_unit)
  50.             co = _settextcolor(avl_men_ready);
  51.         else
  52.             co = _settextcolor(avl_men_letter);
  53.         sprintf(msg,fmt, k + '0', w[i].name);
  54.         _outtext(msg);
  55.         ++k;
  56.         }
  57.     _settextcolor(co);
  58. }
  59.                 
  60.  
  61. int AVL_UNIT(AVL_BIND_PTR w, int r)
  62. {
  63.         short x ;
  64.         short no = 0;
  65.         short ch, cols = 0, rows;
  66.         AVL_WIN_PTR hw, hw2;
  67.         if (r < 10)
  68.             rows = r;
  69.         else 
  70.             rows = 9;
  71.         avl_size = r;
  72.         avl_cur_unit = 0;
  73.  
  74.         /* Compute the maximum window's length */
  75.         for(x = 0; x < r; ++x)  
  76.             if ((no = strlen(w[x].name)) > cols)
  77.                 cols = no;
  78.  
  79.         cols += 4;
  80.         hw2 = AVL_MAKE_WINDOW("",15,55,15+9,55+24,avl_wnd_bk_color,avl_wnd_color);
  81.         _outtext(" Use the arrow keys to\n");
  82.         _outtext(" go  over  the  units.\n");
  83.         _outtext("\n");
  84.         _outtext(" Press  <enter>  to\n");
  85.         _outtext(" select  an  unit  or\n");
  86.         _outtext(" type  the  unit's no.\n");
  87.         _outtext("\n");
  88.         _outtext(" Press ESC to  cancel.");
  89.         hw = AVL_MAKE_WINDOW("",3,avl_menu[3].c,3+rows+1,avl_menu[3].c+cols+5,avl_wnd_bk_color,avl_wnd_color);
  90.  
  91.         while ( 1 )  {
  92.             AVL_SHOW_UNIT(w,cols-4);
  93.             ch = getch();
  94.             x = (last - first + 1);
  95.             if ((ch >= '1' && ch <= (x + '0')) || (ch == 13)) {
  96.                 if (ch != 13)
  97.                     avl_cur_unit += (ch - '0' - 1);
  98.                 AVL_DEL_WINDOW(hw);
  99.                 AVL_DEL_WINDOW(hw2);
  100.                 return avl_cur_unit;
  101.                 }
  102.             else {
  103.                 if (ch == 0 || ch == 0xE0) {
  104.                     ch = getch();
  105.                     switch( ch ) {
  106.                            case 73 : /* Page Up */ 
  107.                                avl_cur_unit -= rows;
  108.                                if (avl_cur_unit < 0)  
  109.                                 avl_cur_unit = avl_size - 1;
  110.                                break;
  111.                            case 81 : /* Page Down */ 
  112.                                avl_cur_unit += rows;
  113.                                if (avl_cur_unit >= avl_size)
  114.                                    avl_cur_unit = 0;
  115.                                break;
  116.                         case 72 : /* Up */ 
  117.                             if (--avl_cur_unit < 0)  
  118.                                 avl_cur_unit = avl_size - 1;
  119.                             break;
  120.                         case 80 : /* Down */ 
  121.                             if (++avl_cur_unit >= avl_size)
  122.                                 avl_cur_unit = 0;
  123.                             break;
  124.                         default : putchar(7); break;
  125.                         }
  126.                     continue;
  127.                     }
  128.                 if (ch == 27)  {
  129.                     AVL_DEL_WINDOW(hw);
  130.                     AVL_DEL_WINDOW(hw2);
  131.                     return -1;
  132.                     }
  133.                 putch(7);
  134.                 continue;
  135.                 }
  136.             }
  137. }            
  138.  
  139.  
  140.  
  141. void AVL_MAKE_BNAME(char *s, char *r)
  142. {
  143.     short i, j = 0;
  144.     char msg[50];
  145.     char *p;
  146.     p = r;
  147.     i = strlen(s) - 1;
  148.     while (*(s + i) != ' ') --i;
  149.     for(++i; *(s + i) != '\0'; ++i, ++r)
  150.         *r = *(s + i);
  151.     *r = '\0';
  152.     r = p;
  153.     if (strlen(p) > 10) {
  154.         i = strlen(p);
  155.         if (*(p + --i) == 'k' &&
  156.             *(p + --i) == 's' &&
  157.             *(p + --i) == 'a' &&
  158.             *(p + --i) == 't' &&
  159.             *(p + --i) == '_' &&
  160.             *(p + --i) == 'e' &&
  161.             *(p + --i) == 'l' &&
  162.             *(p + --i) == 'd' &&
  163.             *(p + --i) == 'i' &&
  164.             *(p + --i) == '_')  
  165.             *(p + i) = '\0';
  166.         }
  167. }    
  168.  
  169. void AVL_DELETE_ONE(short j, AVL_UNITDT_PTR w)
  170. {
  171.     short k;
  172.     w -> ns -= 1;
  173.     for(k = j; k < w -> ns; ++k) {
  174.         w -> s[k].status   = w -> s[k + 1].status; 
  175.         w -> s[k].is_main  = w -> s[k + 1].is_main;
  176.         strcpy(w -> s[k].fu,w -> s[k + 1].fu);
  177.         w -> s[k].cdate[0] = w -> s[k + 1].cdate[0];
  178.         w -> s[k].cdate[1] = w -> s[k + 1].cdate[1];
  179.         w -> s[k].cdate[2] = w -> s[k + 1].cdate[2];
  180.         w -> s[k].cdate[3] = w -> s[k + 1].cdate[3];
  181.         w -> s[k].cdate[4] = w -> s[k + 1].cdate[4];
  182.         }
  183. }    
  184.     
  185.  
  186. void AVL_DELETE_BNAME(short i,AVL_UNITDT_PTR w,char *s)
  187. {
  188.     short j, k;
  189.     char msg[50];
  190.     for(j = i + 1; j < w -> ns; ++j)  {
  191.         if (w -> s[j].is_main == ' ' && 
  192.             w -> s[j].fu[0] == 'b' &&
  193.             w -> s[j].fu[1] == 'i' &&
  194.             w -> s[j].fu[2] == 'n')  {
  195.             AVL_MAKE_BNAME(w -> s[j].fu,msg);
  196.             if (!strcmp(s,msg)) { 
  197.                 AVL_DELETE_ONE(j,w);
  198.                 break;
  199.                 }
  200.             }
  201.         }
  202. }
  203.                                 
  204. char *AVL_BIND_SELECT(AVL_UNITDT_PTR w)
  205. {
  206.     short rows, cols;
  207.     short i, j, k, n = 0, nc = 0;
  208.  
  209.     char msg[50];
  210.  
  211.     static AVL_BIND_SIZE r[AVL_MAX_UNITS];
  212.     AVL_BIND_SIZE c[AVL_MAX_UNITS];
  213.      
  214.     /* Pick obsolete units for compilation */
  215.     for(i = 0; i < w -> ns; ++i)  {
  216.         if (!strcmp(w -> s[i].fu,"subprogram DUMMY")) {
  217.             AVL_DELETE_ONE(i,w);
  218.             --i;
  219.             continue;
  220.             }
  221.         if (w -> s[i].status == 'O' && w -> s[i].is_main == 'M')   {
  222.                 if (nc >= AVL_MAX_UNITS) {
  223.                     AVL_ERROR("Too many units. Reinitialize library!");
  224.                     return;
  225.                     }
  226.                 c[nc].st = 'C';
  227.                 AVL_MAKE_BNAME(w -> s[i].fu,c[nc].name);
  228.                 /* An obsolete unit may be in "s" twice,
  229.                    therefore, it must be deleted */
  230.                 AVL_DELETE_ONE(i,w); /* Now there may be one left */
  231.                 AVL_DELETE_BNAME(-1,w,c[nc].name);
  232.                 ++nc;
  233.                 }
  234.         }
  235.  
  236.     for(i = 0; i < w -> ns; ++i)  
  237.         if (w -> s[i].status == 'A' && w -> s[i].is_main == 'M')   {
  238.             /*  Subprogram ready for binding */
  239.             if (n >= AVL_MAX_UNITS) {
  240.                 AVL_ERROR("Too many units. Reinitialize library!");
  241.                 return;
  242.                 }
  243.             r[n].st = 'B';
  244.             AVL_MAKE_BNAME(w -> s[i].fu,r[n].name);
  245.             AVL_DELETE_ONE(i,w);
  246.             --i;
  247.             ++n;
  248.             }
  249.  
  250.  
  251.     /*  Delete units that are already binded and ready for execution */
  252. /*  Allow all units to be binded 
  253.     for(i = 0; i < w -> ns; ++i)  
  254.         if (w -> s[i].status == 'A' && w -> s[i].is_main == ' ')   {
  255.             AVL_MAKE_BNAME(w -> s[i].fu, msg);
  256.             for(j = 0; j < n; ++j)  
  257.                 if (!strcmp(msg,r[j].name))  {
  258.                     --n;
  259.                     AVL_DELETE_ONE(i,w);
  260.                     for(k = j; k < n; ++k)  {
  261.                         r[k].st = r[k + 1].st;
  262.                         strcpy(r[k].name,r[k+1].name);
  263.                         }
  264.                     --i;
  265.                     break;
  266.                     }
  267.             }                
  268. */
  269.  
  270.     if (n > 0)
  271.         i = AVL_UNIT(r,n);
  272.     else {
  273.         i = -1;
  274.         AVL_ERROR("First compile any executable program unit.");
  275.         }
  276.     if (i >= 0)
  277.         return r[i].name;
  278.     return NULL;
  279. }
  280.         
  281.  
  282. void AVL_BIND()
  283. {
  284.     AVL_EDIT_WINDOW_PTR ww;
  285.     AVL_WIN_PTR temp;
  286.     char msg[100];
  287.     char *bunit;
  288.     char *opts[17];
  289.     AVL_UNITDT w;
  290.     short cmd_ret_code, i;
  291.     FILE *fp, *fopen();
  292.     avl_blank_line[0] = '\0';
  293. /*    w = &avl_windows[avl_window];  */
  294.     w.ns = 0;
  295.     opts[0] = "Adalib2";
  296.     opts[1] = "-l";
  297.     opts[2] = avl_dir_library;
  298.     opts[3] = NULL;
  299.     unlink("gwada.smm");
  300.     temp = AVL_MAKE_WINDOW(" Binding ",5,1,9,80,avl_wnd_bk_color,avl_wnd_color);
  301.     _outtext("  Searching library. Please, wait a moment...\n");
  302.     if (AVL_EX_UNIT("ADALIB2", opts))  {
  303.         AVL_DEL_WINDOW(temp);
  304.         msg[0] = '\0';
  305.         AVL_MAKE_UNIT_DATE(&w);
  306.         if (w.ns > 0)  {
  307.             bunit = AVL_BIND_SELECT(&w);
  308.             if (bunit != NULL)  {
  309.                 sprintf(msg," %s\n", bunit);
  310.                 temp = AVL_MAKE_WINDOW(" Binding ",5,1,8,80,avl_wnd_bk_color,avl_wnd_color);
  311.                 _outtext(msg);
  312.                 opts[0] = "Adabind";
  313.                 opts[1] = "-m";
  314.                 opts[2] = bunit;
  315.                 opts[3] = avl_dir_library;
  316.                 opts[4] = NULL;
  317.                 if (AVL_EX_UNIT("ADABIND", opts))  ;
  318.                 AVL_DEL_WINDOW(temp);
  319.                 }
  320.             }            
  321.         else  {
  322.             AVL_ERROR("First compile any executable program unit.");
  323.             AVL_DEL_WINDOW(temp);
  324.             }
  325.         }
  326.     avl_open_error_file = 0;
  327. }
  328.     
  329.